import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { ConfigProvider, Space } from 'antd-v4';
import React, { useContext, useImperativeHandle } from 'react';

var addArrayKeys = function addArrayKeys(doms) {
  return doms.map(function (dom, index) {
    if (! /*#__PURE__*/React.isValidElement(dom)) {
      // eslint-disable-next-line react/no-array-index-key
      return _jsx(React.Fragment, {
        children: dom
      }, index);
    }

    return /*#__PURE__*/React.cloneElement(dom, _objectSpread({
      // eslint-disable-next-line react/no-array-index-key
      key: index
    }, dom === null || dom === void 0 ? void 0 : dom.props));
  });
};
/**
 * 一般用于放多个按钮
 *
 * @param
 */


var FieldOptions = function FieldOptions(_ref, ref) {
  var text = _ref.text,
      type = _ref.mode,
      render = _ref.render,
      fieldProps = _ref.fieldProps;

  var _useContext = useContext(ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var className = getPrefixCls('pro-field-option');
  useImperativeHandle(ref, function () {
    return {};
  });

  if (render) {
    var doms = render(text, _objectSpread({
      mode: type
    }, fieldProps), _jsx(_Fragment, {}));

    if (!doms || (doms === null || doms === void 0 ? void 0 : doms.length) < 1 || !Array.isArray(doms)) {
      return null;
    }

    return _jsx(Space, {
      size: 16,
      className: className,
      children: addArrayKeys(doms)
    });
  }

  if (!text || !Array.isArray(text)) {
    if (! /*#__PURE__*/React.isValidElement(text)) {
      return null;
    }

    return text;
  }

  return _jsx(Space, {
    size: 16,
    className: className,
    children: addArrayKeys(text)
  });
};

export default /*#__PURE__*/React.forwardRef(FieldOptions);